import React, { Suspense, lazy } from 'react'
import type { RouteObject } from 'react-router-dom'
import Loading from '../components/loading'
import LayoutComp from '@/components/LayoutComp';
import Author from './Author';

// react-router 6 https://reactrouter.com/
const Welcome = lazy(() => import('@/pages/Welcome'))
const About = lazy(() => import('../pages/about'))
const NetdiskInfo = lazy(() => import('@/pages/Netdisk'))
const NetworkQueryInfo = lazy(() => import('@/pages/NetworkQueryInfo'))
const NetworkDiskTree = lazy(() => import('@/pages/NetworkDiskTree'))
const NetworkDiskRoleManagement = lazy(() => import('@/pages/NetworkDiskRoleManagement'))
const Login = lazy(() => import('@/pages/login'))
const Page404 = lazy(() => import('@/pages/Page404'))
const UserManger = lazy(() => import('@/pages/UserManger'))
const BannerManger = lazy(() => import('@/pages/bannerManger'))

const Element = (props: { child: React.ReactChild }) => {
  return <Suspense fallback={<Loading />}>{props.child}</Suspense>
}

interface baseRoutersType extends RouteObject {
  mate?: {
    title?: string;
    icon?: React.ReactNode;
    noLogin?: boolean;
    hideMenu?: boolean;
  }
}

export const routes: baseRoutersType[] = [
  {
    path: '/',
    element: <Author><LayoutComp /></Author>,
    children: [
      {
        index: true,
        element: <Element child={<Welcome />} />,
      },
      {
        path: '/About',
        element: <Element child={<About />} />,
      },
      {
        path: '/NetdiskInfo', // 网盘录入信息模块
        element: <Element child={<NetdiskInfo />} />,
      },
      {
        path: '/NetworkQueryInfo', // 网盘查询信息
        element: <Element child={<NetworkQueryInfo />} />,
      },
      {
        path: '/NetworkDiskTree', // 网盘树形图页面
        element: <Element child={<NetworkDiskTree />} />,
      },
      {
        path: '/NetworkDiskRoleManagement', // 网盘角色管理
        element: <Element child={<NetworkDiskRoleManagement />} />,
      },
      {
        path: '/Welcome',
        element: <Element child={<Welcome />} />,
      },
      {
        path: '*',
        element: <Element child={<Page404 />} />
      },
      {
        path: '/userManger', // 用户管理模块
        element: <Element child={<UserManger />} />,
      },
      {
        path: '/bannerManger', // 轮播图管理模块
        element: <Element child={<BannerManger />} />,
      },
    ]
  },
  {
    path: '/login',
    element: <Element child={<Login />} />,
  }
];

export default routes;